package com.infovane.action;

import java.util.List;

import com.infovane.base.BaseAction;
import com.infovane.model.PageModel;
import com.infovane.model.TArticle;
import com.infovane.model.TArticleComment;
import com.infovane.service.ArticleCommentService;
import com.infovane.utils.PagingModule;
import com.infovane.utils.SystemConstant;

public class ArticleCommentAction extends BaseAction{
	private ArticleCommentService articleCommentService;
	
	public ArticleCommentService getArticleCommentServie() {
		return articleCommentService;
	}

	public void setArticleCommentService(ArticleCommentService articleCommentService) {
		this.articleCommentService = articleCommentService;
	}

	/**
	 * 获取文章评论
	 * */
	public  String getComment(){
		Long articleid=0L;
		try{
			articleid=Long.parseLong(httpServletRequest.getParameter("articleId"));
		}catch(NullPointerException e){
			String warn="没有该文章的相关评论!";
			httpServletRequest.setAttribute("WARN", warn);
			return ERROR;
		}
		String strCurrentPage=httpServletRequest.getParameter("currentPage");
		int currentPage;
		if(strCurrentPage==null||strCurrentPage.equals("")){
			currentPage=1;
		}else{
			try{
				currentPage=Integer.parseInt(strCurrentPage.intern());
			}catch(NumberFormatException e){
				currentPage=1;
			}
		}
		List<TArticleComment> list=this.articleCommentService.getArticleComment(articleid,currentPage,SystemConstant.PAGE_SIZE);
		if(list!=null&&list.size()>0){
			int count=this.articleCommentService.getCount(articleid);
			int maxPage=PagingModule.maxPageSize(count);
			PageModel<TArticleComment> pm=new PageModel<TArticleComment>(list,maxPage);
			httpServletRequest.setAttribute("pm", pm);
			return SUCCESS;
		}
		return ERROR;
	} 

}
